import get_data as gd
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.pyplot import MultipleLocator

plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['font.serif'] = ['KaiTi']

def draw_daily_add_line(event):
    datas = gd.read_data2()["dailyNewAddHistory"]
    x1 = []
    y1 = []
    y2 = []
    y3 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["country"]))
        y2.append(float(data["hubei"]))
        y3.append(float(data["notHubei"]))
        i+=1
    plt.figure(num = "疫情每日新增图")
    plt.xlabel("日期，2019.1.20至今")
    plt.ylabel("人数")
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,16000)
    plt.plot(x1,y1,label = "全国")
    plt.plot(x1,y2,label = "湖北地区")
    plt.plot(x1,y3,label = "非湖北地区")
    plt.xticks([])
    plt.legend()
    plt.show()


def draw_now_confirm_line(event):
    datas = gd.read_data2()["dailyHistory"]
    x1 = []
    y1 = []
    y2 = []
    y3 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["country"]["nowConfirm"]))
        y2.append(float(data["hubei"]["nowConfirm"]))
        y3.append(float(data["notHubei"]["nowConfirm"]))
        i+=1
    plt.figure(num = "疫情现有确诊图")
    plt.xlabel("日期，2019.1.20至今")
    plt.ylabel("人数")
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,65000)
    plt.plot(x1,y1,label = "全国")
    plt.plot(x1,y2,label = "湖北地区")
    plt.plot(x1,y3,label = "非湖北地区")
    plt.xticks([])
    
    plt.legend()
    plt.show()

def draw_country_sum_line(event):
    datas = gd.read_data2()["chinaDayList"]
    x1 = []
    y1 = []
    y2 = []
    y3 = []
    y4 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["nowConfirm"]))
        y2.append(float(data["suspect"]))
        y3.append(float(data["dead"]))
        y4.append(float(data["heal"]))
        i+=1
    plt.figure(num = "疫情全国累计图")
    plt.xlabel("日期，2019.1.20至今")
    plt.ylabel("人数")
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,85000)
    plt.plot(x1,y1,label = "全国现存确诊",color = "red")
    plt.plot(x1,y2,label = "全国现存疑似",color = "#e8b004")
    plt.plot(x1,y3,label = "全国累计死亡",color = "black")
    plt.plot(x1,y4,label = "全国累计治愈",color = "green")
    plt.xticks([])
    plt.legend()
    plt.show()

def draw_rate_line(event):
    datas = gd.read_data2()["chinaDayList"]
    x1 = []
    y1 = []
    y2 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["deadRate"]))
        y2.append(float(data["healRate"]))
        i+=1
    plt.figure(num = "全国治愈死亡率图")
    plt.xlabel("日期，2019.1.20至今")
    plt.ylabel("百分比")
    y_major_locator=MultipleLocator(4)
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.yaxis.set_major_locator(y_major_locator)
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0, int(float(y2[len(y2)-1]))+5)
    plt.plot(x1,y1,label = "全国死亡率",color = "black")
    plt.plot(x1,y2,label = "全国治愈率",color = "green")
    plt.xticks([])
    plt.legend()
    plt.show()



def  draw_pie_picture_one():
    datas = gd.get_news()
    label = datas[2]
    value = datas[3]
    color = ["red","green"]
    plt.figure(figsize = (6,6),num = "北京市确诊病例男女比例")
    color2 = ["red","green","blue","yellow"]
    plt.pie(value,labels=label,colors=color,autopct='%1.1f%%',radius =0.8)
    plt.show()


def draw_pie_picture_two():
    value = gd.get_news()[4]
    label = ["5岁以下","6岁至17岁","18岁至59岁","60岁及以上"]
    color = ["red","green","blue","yellow"]
    plt.figure(figsize = (6,6),num = "北京市确诊病例年龄比例")
    plt.pie(value, labels = label, colors = color,autopct='%1.1f%%',radius =0.8)
    plt.show()
   

def draw_foreign_country(event):
    datas = gd.read_data4()["globalDailyHistory"]
    x1 = []
    y1 = []
    y2 = []
    y3 = []
    y4 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["all"]["confirm"]))
        y2.append(float(data["all"]["dead"]))
        y3.append(float(data["all"]["heal"]))
        y4.append(float(data["all"]["newAddConfirm"]))
        i+=1

    plt.figure(num = "国外疫情累计图")
    plt.xlabel("日期，2019.1.28至今")
    plt.ylabel("百分比")
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0,int(y1[len(y1)-1])+5000)
    plt.plot(x1,y1,label = "国外确诊总数")
    plt.plot(x1,y2,label = "国外死亡总数")
    plt.plot(x1,y3,label = "国外治愈总数")
    plt.plot(x1,y4,label = "国外每日新增")
    plt.xticks([])
    
    plt.legend()
    plt.show()

def draw_foreign_rate(event):
    datas = gd.read_data4()["globalDailyHistory"]
    x1 = []
    y1 = []
    y2 = []
    i=0
    for data in datas:
        x1.append(i+1)
        y1.append(float(data["all"]["deadRate"]))
        y2.append(float(data["all"]["healRate"]))
        i+=1
    plt.figure(num = "国外治愈死亡率图")
    plt.xlabel("日期，2019.1.28至今")
    plt.ylabel("百分比")
    y_major_locator=MultipleLocator(3)
    ax = plt.gca()
    ax.spines["top"].set_color("none")
    ax.spines["right"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.yaxis.set_major_locator(y_major_locator)
    plt.xlim(1,(len(x1)+1))
    plt.ylim(0, int(float(y2[len(y2)-1]))+5)
    plt.plot(x1,y1,label = "国外死亡率",color = "black")
    plt.plot(x1,y2,label = "国外治愈率",color = "green")
    plt.xticks([])
    plt.legend()
    plt.show()
